// pages/cardPackage/cardPackage.js
const api = require('../../utils/interface.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardList_z:[],
    cardList_f:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#000000',
      backgroundColor: "#ffffff"
    })
    this.getCardList()
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      isShow:false
    })
    console.log(prevPage)

  },
  go_cardList(e){
    let type = e.currentTarget.dataset.type
  
    wx.navigateTo({
      url: './cardList/cardList?type=' + type,
    })
  },
  go_memberCard(e){
    let uuid = e.currentTarget.dataset.uuid
    let cardId = e.currentTarget.dataset.cardid
    let productId = e.currentTarget.dataset.productid
    let productName = e.currentTarget.dataset.productname
    let index = e.currentTarget.dataset.index
    console.log(productId)
    console.log(productName)
    wx.navigateTo({
      url: '/pages/memberCard/memberCard?uuid=' + uuid + '&type=1&cardId=' + cardId + '&productId=' + productId + '&name=' + productName+'&index='+index,
    })
  },
  // 获取会员卡列表
  getCardList(){
    wx.showLoading({
      title: '加载中...',
    })
    let user = wx.getStorageSync('userInfo')
    api.getMemberInfoCard({ memberId: user.id }).then(res=>{
      wx.hideLoading()
      console.log(res.data,"我的卡包")
      if (res.data.result&&res.data.result.length){
        this.data.cardList_f = []
        this.data.cardList_z = []
        res.data.result.map(item => {
          if (item.parentId == 0) {
            this.data.cardList_z.push(item)
          } else {
            this.data.cardList_f.push(item)
          }
          switch (item.productName) {
            case '汽油':
              item.color = "#4A8BFC"
              break;
            case '柴油':
              item.color = "#F56C6C"
              break;
            case 'LNG':
              item.color = "#02B663"
              break;
          }
        })
        console.log(this.data.cardList_z)
        this.setData({
          cardList_z: this.data.cardList_z,
          cardList_f: this.data.cardList_f
        })
      }
      
    })
  },
})